package request;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 *
 * 请求头数据的获取2
 *
 * @author Mc.Chai
 * @program: JavaWeb
 * @create 2022-03-20-17:16 17:16
 */
    @WebServlet("/myRequest4")
    public class MyRequest4 extends HttpServlet {
        @Override
        protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        }

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //获取请求头数据：referer
        String referer = request.getHeader("referer");
        System.out.println(referer);

        //防止盗链
        if(referer!=null){
            if (referer.contains("day09")){
                System.out.println("正常网址的跳转");
            }else{
                System.out.println("想偷我的网址");
            }
        }
    }
}
